package com.monitor.action.admin;

import java.io.PrintWriter;

import com.monitor.action.MonitorActionSupport;
import com.monitor.po.User;
import com.monitor.service.UserService;
import com.monitor.util.Constants;
import com.monitor.util.Pager;

public class UserManageAction extends MonitorActionSupport {

	private static final long serialVersionUID = 8002627222810951993L;
	private int type = 0;
	private UserService userService;
	private Pager<User> users;
	private int cPage;
	private long uid;

	@Override
	public String execute() throws Exception {
		cPage = cPage < 1 ? 1 : cPage;
		users = userService.getUserByType(type, Constants.DEFAULT_PAGESIEZE, cPage);
		return SUCCESS;
	}

	public void openVip() throws Exception {
		PrintWriter out = getWriter();
		int count = userService.setUserVip(uid, true);
		if (count > 0) {
			out.print("success");
		} else {
			out.print("faild");
		}
		out.flush();
		out.close();
	}

	public void closeVip() throws Exception {
		PrintWriter out = getWriter();
		int count = userService.setUserVip(uid, false);
		if (count > 0) {
			out.print("success");
		} else {
			out.print("faild");
		}
		out.flush();
		out.close();
	}

	public void rebind() throws Exception {
		PrintWriter out = getWriter();
		int count = userService.rebindImei(uid);
		if (count > 0) {
			out.print("success");
		} else {
			out.print("failed");
		}
		out.flush();
		out.close();
	}

	public void deleteUser() throws Exception {
		PrintWriter out = getWriter();
		String saveDir = getSaveDirName();
		int count = userService.deleteUserById(uid, saveDir);
		if (count > 0) {
			out.print("success");
		} else {
			out.print("failed");
		}
		out.flush();
		out.close();
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public Pager<User> getUsers() {
		return users;
	}

	public void setUsers(Pager<User> users) {
		this.users = users;
	}

	public int getcPage() {
		return cPage;
	}

	public void setcPage(int cPage) {
		this.cPage = cPage;
	}

	public long getUid() {
		return uid;
	}

	public void setUid(long uid) {
		this.uid = uid;
	}
}
